package com.huangjue.backend.service.impl;

import com.huangjue.backend.entity.News;
import com.huangjue.backend.mapper.NewsMapper;
import com.huangjue.backend.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsMapper newsMapper;

    /**
     * 获取所有已发布的新闻
     */
    @Override
    public List<News> getAllPublishedNews() {
        return newsMapper.selectAllPublishedNews();
    }

    /**
     * 获取最新的4条已发布新闻
     */
    @Override
    public List<News> getLatestPublishedNews() {
        return newsMapper.selectLatestPublishedNews();
    }

    /**
     * 根据ID获取新闻详情
     */
    @Override
    public News getNewsById(Integer id) {
        return newsMapper.selectNewsById(id);
    }

    /**
     * 更新新闻浏览次数
     */
    @Override
    @Transactional
    public boolean updateNewsViewCount(Integer id) {
        return newsMapper.updateNewsViewCount(id) > 0;
    }
} 